package com.donggua.aichebao.commonui.setting;

import android.content.Context;
import android.content.res.TypedArray;
import android.icu.text.RelativeDateTimeFormatter;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.Checkable;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.view.View;
import org.w3c.dom.Text;
import com.donggua.aichebao.commonui.R;

/**
 * Created by fzh on 2017/8/18.
 */
//com.donggua.aichebao.commonui.setting.DGSettingItemLayout
public class DGSettingItemLayout extends RelativeLayout {
    private TextView tvLeft;
    private View viLine;
    private CheckBox ckRight;
    private final static int DEFUAL_SIZE = 20;
    public DGSettingItemLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        viLine = new View(context);
        RelativeLayout.LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        int lineHeight = (int)context.getResources().getDimension(R.dimen.lineHeight);
        layoutParams.height = lineHeight;
        viLine.setLayoutParams(layoutParams);
        viLine.setBackgroundColor(0xff000000);
        this.addView(viLine);
        TypedArray ta = context.obtainStyledAttributes(attrs,R.styleable.CustomTextView);
        String text = ta.getString(R.styleable.CustomTextView_customText);
        int textSize =(int) ta.getDimension(R.styleable.CustomTextView_customTextSize,DEFUAL_SIZE);
        int color = ta.getColor(R.styleable.CustomTextView_customTextColor,0xff000000);
        RelativeLayout.LayoutParams layoutParams1 = getMyLayoutParams();
        layoutParams1.addRule(RelativeLayout.ALIGN_PARENT_LEFT,RelativeLayout.TRUE);
        layoutParams1.addRule(RelativeLayout.CENTER_VERTICAL,RelativeLayout.TRUE);
        tvLeft = new TextView(context);
        tvLeft.setText(text);
        tvLeft.setTextSize( TypedValue.COMPLEX_UNIT_PX,textSize);
        tvLeft.setTextColor(color);
        tvLeft.setLayoutParams(layoutParams1);
        this.addView(tvLeft);
        ckRight = new CheckBox(context);
        RelativeLayout.LayoutParams layoutParams2 = getMyLayoutParams();
        layoutParams2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT,RelativeLayout.TRUE);
        layoutParams2.addRule(RelativeLayout.CENTER_VERTICAL,RelativeLayout.TRUE);
        ckRight.setLayoutParams(layoutParams2);
        this.addView(ckRight);
    }
    private static RelativeLayout.LayoutParams getMyLayoutParams(){
        LayoutParams layoutParams = new LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        return layoutParams;
    }

    public void setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener listener){
        ckRight.setOnCheckedChangeListener(listener);
    }

    public void setId(int id){
        ckRight.setId(id);
    }
}
